package com.systemmanger.controller;

import com.bean.WmsTGroup;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.systemmanger.service.ZuGuanLiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("guanli")
public class ZuGuanLiController {
    @Autowired
    ZuGuanLiService zuGuanLiService;

    @RequestMapping("Group.do")
    public String page(HttpSession httpSession,
         @RequestParam(required = false,defaultValue = "1",value ="pageNum" )Integer pageNum,
         @RequestParam(defaultValue = "15",value = "pageSize")Integer pageSize,
                       String groupName,String groupID) {
        PageInfo<WmsTGroup> pageInfo=new PageInfo<>() ;
        if(pageNum==null || pageNum<0){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=15;
        }
        WmsTGroup wmsTGroup=new WmsTGroup();
        wmsTGroup.setGroupName(groupName);
        wmsTGroup.setGroupID(groupID);
        httpSession.setAttribute("groupName",groupName);
        httpSession.setAttribute("groupID",groupID);
        //引入分页查询插件， pageNum是第几页，pageSize是每页显示多少条
        PageHelper.startPage(pageNum,pageSize);
        List<WmsTGroup> list=zuGuanLiService.page(wmsTGroup);
        pageInfo=new PageInfo<>(list,pageSize);
        System.out.println(list);
        System.out.println(pageInfo);
        httpSession.setAttribute("pageInfo",pageInfo);
        return "guanli/classManger";
    }

    @RequestMapping("Group1.do")
    @ResponseBody
    public List<WmsTGroup> returnPage(String groupID){
        WmsTGroup wmsTGroup=new WmsTGroup();
        wmsTGroup.setGroupID(groupID);
        return  zuGuanLiService.page(wmsTGroup);
    }


}
